package com.yilizhiyou.model;

import java.util.Map;
import java.util.HashMap;

/**
 * 用户偏好模型
 * 用于存储和分析用户的旅游偏好
 * 
 * @author 伊犁智游开发团队
 * @since 1.0.0
 */
public class UserPreference {
    
    // 用户ID
    private String userId;
    
    // 景点类型偏好权重 (自然风光、人文景观等)
    private Map<String, Double> typePreferences;
    
    // 价格偏好 (1-5，1表示经济型，5表示豪华型)
    private Double pricePreference;
    
    // 活动强度偏好 (1-5，1表示轻松，5表示高强度)
    private Double activityIntensity;
    
    // 文化兴趣偏好 (1-5，1表示低，5表示高)
    private Double culturalInterest;
    
    // 自然风光偏好 (1-5，1表示低，5表示高)
    private Double natureInterest;
    
    // 历史古迹偏好 (1-5，1表示低，5表示高)
    private Double historicalInterest;
    
    // 美食偏好 (1-5，1表示低，5表示高)
    private Double foodInterest;
    
    // 摄影偏好 (1-5，1表示低，5表示高)
    private Double photographyInterest;
    
    // 交通方式偏好 (walking, driving, public_transport)
    private String transportPreference;
    
    // 旅行时长偏好 (1-7天)
    private Integer preferredDuration;
    
    // 同行人数
    private Integer groupSize;
    
    // 年龄组 (young, middle, senior)
    private String ageGroup;
    
    // 历史访问记录
    private Map<String, Integer> visitHistory;
    
    // 评分记录
    private Map<String, Double> ratingHistory;
    
    public UserPreference() {
        this.typePreferences = new HashMap<>();
        this.visitHistory = new HashMap<>();
        this.ratingHistory = new HashMap<>();
        
        // 设置默认偏好
        this.pricePreference = 3.0;
        this.activityIntensity = 3.0;
        this.culturalInterest = 3.0;
        this.natureInterest = 3.0;
        this.historicalInterest = 3.0;
        this.foodInterest = 3.0;
        this.photographyInterest = 3.0;
        this.transportPreference = "driving";
        this.preferredDuration = 3;
        this.groupSize = 2;
        this.ageGroup = "middle";
    }
    
    public UserPreference(String userId) {
        this();
        this.userId = userId;
    }
    
    // Getters and Setters
    public String getUserId() {
        return userId;
    }
    
    public void setUserId(String userId) {
        this.userId = userId;
    }
    
    public Map<String, Double> getTypePreferences() {
        return typePreferences;
    }
    
    public void setTypePreferences(Map<String, Double> typePreferences) {
        this.typePreferences = typePreferences;
    }
    
    public Double getPricePreference() {
        return pricePreference;
    }
    
    public void setPricePreference(Double pricePreference) {
        this.pricePreference = pricePreference;
    }
    
    public Double getActivityIntensity() {
        return activityIntensity;
    }
    
    public void setActivityIntensity(Double activityIntensity) {
        this.activityIntensity = activityIntensity;
    }
    
    public Double getCulturalInterest() {
        return culturalInterest;
    }
    
    public void setCulturalInterest(Double culturalInterest) {
        this.culturalInterest = culturalInterest;
    }
    
    public Double getNatureInterest() {
        return natureInterest;
    }
    
    public void setNatureInterest(Double natureInterest) {
        this.natureInterest = natureInterest;
    }
    
    public Double getHistoricalInterest() {
        return historicalInterest;
    }
    
    public void setHistoricalInterest(Double historicalInterest) {
        this.historicalInterest = historicalInterest;
    }
    
    public Double getFoodInterest() {
        return foodInterest;
    }
    
    public void setFoodInterest(Double foodInterest) {
        this.foodInterest = foodInterest;
    }
    
    public Double getPhotographyInterest() {
        return photographyInterest;
    }
    
    public void setPhotographyInterest(Double photographyInterest) {
        this.photographyInterest = photographyInterest;
    }
    
    public String getTransportPreference() {
        return transportPreference;
    }
    
    public void setTransportPreference(String transportPreference) {
        this.transportPreference = transportPreference;
    }
    
    public Integer getPreferredDuration() {
        return preferredDuration;
    }
    
    public void setPreferredDuration(Integer preferredDuration) {
        this.preferredDuration = preferredDuration;
    }
    
    public Integer getGroupSize() {
        return groupSize;
    }
    
    public void setGroupSize(Integer groupSize) {
        this.groupSize = groupSize;
    }
    
    public String getAgeGroup() {
        return ageGroup;
    }
    
    public void setAgeGroup(String ageGroup) {
        this.ageGroup = ageGroup;
    }
    
    public Map<String, Integer> getVisitHistory() {
        return visitHistory;
    }
    
    public void setVisitHistory(Map<String, Integer> visitHistory) {
        this.visitHistory = visitHistory;
    }
    
    public Map<String, Double> getRatingHistory() {
        return ratingHistory;
    }
    
    public void setRatingHistory(Map<String, Double> ratingHistory) {
        this.ratingHistory = ratingHistory;
    }
    
    /**
     * 更新用户对某个景点的访问记录
     */
    public void addVisit(String spotId) {
        visitHistory.put(spotId, visitHistory.getOrDefault(spotId, 0) + 1);
    }
    
    /**
     * 更新用户对某个景点的评分
     */
    public void addRating(String spotId, Double rating) {
        ratingHistory.put(spotId, rating);
    }
    
    /**
     * 计算与另一个用户偏好的相似度
     */
    public double calculateSimilarity(UserPreference other) {
        double similarity = 0.0;
        int factors = 0;
        
        // 价格偏好相似度
        similarity += 1.0 - Math.abs(this.pricePreference - other.pricePreference) / 4.0;
        factors++;
        
        // 活动强度相似度
        similarity += 1.0 - Math.abs(this.activityIntensity - other.activityIntensity) / 4.0;
        factors++;
        
        // 文化兴趣相似度
        similarity += 1.0 - Math.abs(this.culturalInterest - other.culturalInterest) / 4.0;
        factors++;
        
        // 自然风光兴趣相似度
        similarity += 1.0 - Math.abs(this.natureInterest - other.natureInterest) / 4.0;
        factors++;
        
        // 历史古迹兴趣相似度
        similarity += 1.0 - Math.abs(this.historicalInterest - other.historicalInterest) / 4.0;
        factors++;
        
        // 美食兴趣相似度
        similarity += 1.0 - Math.abs(this.foodInterest - other.foodInterest) / 4.0;
        factors++;
        
        // 摄影兴趣相似度
        similarity += 1.0 - Math.abs(this.photographyInterest - other.photographyInterest) / 4.0;
        factors++;
        
        return factors > 0 ? similarity / factors : 0.0;
    }
}
